<?php
	include_once'config/db.php';
	include_once'functions/loginLib.php';
	
	if(isset($_SESSION['logged_in'])) header('location:index.php');
	if(isset($_REQUEST['login'])){
		if($_REQUEST['user']==$_REQUEST['user']){
			$funct=login_mod($_REQUEST['user'],$_REQUEST['pass']);
			if(!empty($funct)){
				$_SESSION['user_id']=$funct['user_id'];
				$_SESSION['user']=$funct['user'];
				$_SESSION['pass']=$funct['pass'];
				$_SESSION['name']=$funct['name'];
				$_SESSION['contact']=$funct['contact'];
				$_SESSION['email']=$funct['email'];
				$_SESSION['picture']=$funct['picture'];
				$_SESSION['logged_in'] = 'logged_in';
				header('location: index.php');	
			}	
		}
		if($_REQUEST['user']==$_REQUEST['user']){
			$funct1=admin_mod($_REQUEST['user'], $_REQUEST['pass']);
				if(!empty($funct1)){
				$_SESSION['admin_id']=$funct1['admin_id'];
				$_SESSION['user']=$funct1['user'];
				$_SESSION['pass']=$funct1['pass'];
				$_SESSION['contact']=$funct1['contact'];
				$_SESSION['email_add']=$funct1['email_add'];
				$_SESSION['e_logged_in'] = 'logged_in';
				header('location: admin/index.php');
				}
		}
		if($_REQUEST['user']==$_REQUEST['user']){
			$funct2=super_mod($_REQUEST['user'], $_REQUEST['pass']);
				if(!empty($funct2)){
				$_SESSION['admin_id']=$funct2['admin_id'];
				$_SESSION['user']=$funct2['user'];
				$_SESSION['pass']=$funct2['pass'];
				$_SESSION['r_logged_in'] = 'logged_in';
				header('location: super-admin/index.php');
		}}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css"/>
<title>Untitled Document</title>
</head>

<body>
<div id="container">
<h3><center>Rizal Technological University</center></h3>
<div id="login">
<p>
  <?php if(isset($error)):?>
<div id="error">You enter empty field</div>
<?php elseif(isset($invalid)):?>
<div id="error">Invalid Login</div>
<?php endif;?>
<form id="form" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  <table width="384" border="0">
    <tr>
      <td width="56"></td>
      <td width="318"><input name="user" type="text" id="user" value="Username" size="40" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="pass" type="password" id="pass" value="Password" size="40" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label for="select">
        <input type="submit" name="login" id="login2" value="Login" class="blue"/>
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><a href="register.php">register for new student</a></td>
    </tr>
  </table>
</form></div></div>
<p>&nbsp;</p>
</body>
</html>